//
//  CarAuditInfoCell.swift
//  TrafficViolation
//
//  Created by eaglelive on 2017/7/4.
//  Copyright © 2017年 eaglelive. All rights reserved.
//

import Foundation
class CarAuditInfoCell: UITableViewCell {
    var license_1,license_2,baoxian,opearBtn:UIButton!
    var remark,reason,address:UITextView!
    var submitAuditBtn:UIButton!
    var reasonView,okView:UIView!
    var money,receiveUser,receivePhone:UITextField!
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCellSelectionStyle.none
        self.layer.borderWidth = 0
        let carLicense = UILabel.init(frame: CGRect(x: oLabelLeft, y: oTop, width: oLabelW, height: oLabelH))
        carLicense.font = oFontSize
        carLicense.text = "行驶证信息"
        self.addSubview(carLicense)
        //证件照片
        license_1 = UIButton.init(frame: CGRect(x: oImgLeft, y:oLabelH + oTop, width: oImgW, height: oImgH))
        license_1.setBackgroundImage(UIImage(named:"xingshizheng1"), for: .normal)
        self.addSubview(license_1)
        
        license_2 = UIButton.init(frame: CGRect(x: oImgLeft, y: oImgH + oLabelH + 2*oTop, width: oImgW, height: oImgH))
        license_2.setBackgroundImage(UIImage(named:"xingshizheng2"), for: .normal)
        self.addSubview(license_2)
        
        let insurance = UILabel.init(frame: CGRect(x: oLabelLeft, y: 2*oImgH + oLabelH + 3*oTop, width: oLabelW, height: oLabelH))
        insurance.font = oFontSize
        insurance.text = "保险单信息"
        self.addSubview(insurance)
        
        baoxian = UIButton.init(frame: CGRect(x: oImgLeft, y: 2*oImgH + 2*oLabelH + 3*oTop, width: oImgW, height: oImgH))
        baoxian.setBackgroundImage(UIImage(named:"xingshizheng1"), for: .normal)
        self.addSubview(baoxian)
        
        let remarkLabel = UILabel.init(frame: CGRect(x: oLabelLeft, y:3*oImgH + 2*oLabelH + 4*oTop, width: oLabelW, height: remarkH))
        remarkLabel.font = oFontSize
        remarkLabel.text = "备注信息"
        self.addSubview(remarkLabel)
        remark = UITextView.init(frame:CGRect(x:oLabelW, y:3*oImgH + 2*oLabelH + 4*oTop, width:oImgW, height:remarkH))
        remark.layer.cornerRadius = 5
        remark.backgroundColor = tableBgColor
        remark.textColor = fontColor
        remark.isEditable = false
        self.addSubview(remark)
        //不可审核时显示
        reasonView = UIView.init(frame:CGRect(x:0, y:3*oImgH + 2*oLabelH + 5*oTop + remarkH, width:kScreenW, height:remarkH))
        reasonView.isHidden = true
        self.addSubview(reasonView)
        
        let reasonLabel = UILabel.init(frame: CGRect(x: oLabelLeft, y:0, width: oLabelW, height: remarkH))
        reasonLabel.font = oFontSize
        reasonLabel.text = "不可办原因"
        reasonView.addSubview(reasonLabel)
        
        reason = UITextView.init(frame:CGRect(x:oLabelW, y:0, width:oImgW, height:remarkH))
        reason.layer.cornerRadius = 5
        reason.backgroundColor = tableBgColor
        reason.textColor = fontColor
        reason.isEditable = false
        reasonView.addSubview(reason)
        //可审核
        okView = UIView.init(frame:CGRect(x:0, y:3*oImgH + 2*oLabelH + 5*oTop + remarkH, width:kScreenW, height:3*cellH + 3*oTop + remarkH))
        okView.isHidden = true
        self.addSubview(okView)
        
        let moneyLabel = UILabel.init(frame: CGRect(x: oLabelLeft, y:0, width: oLabelW, height: cellH))
        moneyLabel.font = oFontSize
        moneyLabel.text = "服务费"
        okView.addSubview(moneyLabel)
        
        money = UITextField.init(frame: CGRect(x: oLabelW, y:0, width: oImgW, height: cellH))
        money.isEnabled = false
        money.backgroundColor = tableBgColor
        money.textColor = fontColor
        money.font = oFontSize
        money.layer.cornerRadius = 5
        okView.addSubview(money)
        
        let receiveUserLabel = UILabel.init(frame: CGRect(x: oLabelLeft, y:cellH + oTop, width: oLabelW, height: cellH))
        receiveUserLabel.font = oFontSize
        receiveUserLabel.text = "收件人姓名"
        okView.addSubview(receiveUserLabel)
        receiveUser = UITextField.init(frame: CGRect(x: oLabelW, y:cellH + oTop, width: oImgW, height: cellH))
        receiveUser.isEnabled = false
        receiveUser.backgroundColor = tableBgColor
        receiveUser.textColor = fontColor
        receiveUser.font = oFontSize
        receiveUser.layer.cornerRadius = 5
        okView.addSubview(receiveUser)
        
        let receivePhoneLabel = UILabel.init(frame: CGRect(x: oLabelLeft, y:2*cellH + 2*oTop, width: oLabelW, height: cellH))
        receivePhoneLabel.font = oFontSize
        receivePhoneLabel.text = "收件人电话"
        okView.addSubview(receivePhoneLabel)
        receivePhone = UITextField.init(frame: CGRect(x: oLabelW, y:2*cellH + 2*oTop, width: oImgW, height: cellH))
        receivePhone.isEnabled = false
        receivePhone.backgroundColor = tableBgColor
        receivePhone.textColor = fontColor
        receivePhone.font = oFontSize
        receivePhone.layer.cornerRadius = 5
        okView.addSubview(receivePhone)

        let addressLabel = UILabel.init(frame: CGRect(x: oLabelLeft, y:3*cellH + 3*oTop, width: oLabelW, height: remarkH))
        addressLabel.font = oFontSize
        addressLabel.text = "收件地址"
        okView.addSubview(addressLabel)
        
        address = UITextView.init(frame:CGRect(x:oLabelW, y:3*cellH + 3*oTop, width:oImgW, height:remarkH))
        address.layer.cornerRadius = 5
        address.backgroundColor = tableBgColor
        address.textColor = fontColor
        address.font = oFontSize
        address.isEditable = false
        okView.addSubview(address)
        //默认：3*oImgH + 2*oLabelH + 6*oTop + remarkH
        opearBtn = UIButton.init(frame: CGRect(x: 20, y: 3*oImgH + 2*oLabelH + 6*oTop + remarkH, width: kScreenW - 40, height: cellH))
        opearBtn.setTitleColor(UIColor.white, for: .normal)
        opearBtn.backgroundColor = appMainColor
        opearBtn.showsTouchWhenHighlighted = true
        opearBtn.layer.cornerRadius = 10
        self.addSubview(opearBtn)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func configCellDateWithModel(_ model:CarAuditModel) {
        let aic = AuditInfoController()
        license_1.sd_setBackgroundImage(with: URL.init(string: "\(projectUrl)/file/download/\(model.driveLicense_1)?tokenID=\(tokenID!)&tokenUserID=\(userID!)"), for: .normal)
        license_2.sd_setBackgroundImage(with: URL.init(string: "\(projectUrl)/file/download/\(model.driveLicense_2)?tokenID=\(tokenID!)&tokenUserID=\(userID!)"), for: .normal)
        baoxian.sd_setBackgroundImage(with: URL.init(string: "\(projectUrl)/file/download/\(model.carInsurance)?tokenID=\(tokenID!)&tokenUserID=\(userID!)"), for: .normal)
        remark.text = "\(model.remark)"
        if model.oprocess.isEmpty {
            opearBtn.setTitle("等待审核", for: .normal)
            opearBtn.isEnabled = false
            opearBtn.backgroundColor = UIColor.lightGray
        }else{
            if "0" == model.oprocess {//不可审核
                opearBtn.frame.origin.y = 3*oImgH + 2*oLabelH + 7*oTop + 2*remarkH
                reasonView.isHidden = false
                reason.text = model.reason
                opearBtn.setTitle("不可办", for: .normal)
                opearBtn.isEnabled = false
                opearBtn.backgroundColor = UIColor.lightGray
            }
            if "1" == model.oprocess {//可审核
                opearBtn.frame.origin.y = 3*oImgH + 2*oLabelH + 10*oTop + 2*remarkH + 3*cellH
                okView.isHidden = false
                money.text = model.samount
                receiveUser.text = model.receiveUser
                receivePhone.text = model.receivePhone
                address.text = model.address
                if "0" ==  model.ostatus{
                    opearBtn.setTitle("去支付", for: .normal)
                    opearBtn.tag = 0
                    opearBtn.addTarget(aic, action: #selector(aic.operatorFun(sender:)), for: UIControlEvents.touchUpInside)
                }
                if "1" == isEmployee {//普通用户登录
                    if "1" == model.ostatus {
                        opearBtn.setTitle("等待处理", for: .normal)
                        opearBtn.isEnabled = false
                        opearBtn.backgroundColor = UIColor.lightGray
                    }
                    if "2" == model.ostatus {
                        opearBtn.setTitle("处理中", for: .normal)
                        opearBtn.backgroundColor = UIColor.lightGray
                        opearBtn.isEnabled = false
                    }
                    if "3" == model.ostatus {
                        opearBtn.setTitle("已处理", for: .normal)
                        opearBtn.isEnabled = false
                        opearBtn.backgroundColor = UIColor.lightGray
                    }
                }
                if "2" == isEmployee {
                    if "1" == model.ostatus {
                        opearBtn.setTitle("抢单", for: .normal)
                        opearBtn.tag = 1
                        opearBtn.addTarget(aic, action: #selector(aic.operatorFun(sender:)), for: UIControlEvents.touchUpInside)
                    }
                    if "2" == model.ostatus {
                        opearBtn.setTitle("完成", for: .normal)
                        opearBtn.tag = 2
                        opearBtn.addTarget(aic, action: #selector(aic.operatorFun(sender:)), for: UIControlEvents.touchUpInside)
                    }
                    if "3" == model.ostatus {
                        opearBtn.setTitle("已完成", for: .normal)
                        opearBtn.backgroundColor = UIColor.lightGray
                        opearBtn.isEnabled = false
                    }
                }
            }
        }
    }
}
